extends CharacterBody2D

signal scored

@onready var timer: Timer = $Timer
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
@onready var pop: AudioStreamPlayer2D = $Pop
@onready var enter: AudioStreamPlayer2D = $Enter
@onready var timer_2: Timer = $Timer2

func _ready() -> void:
	$AnimatedSprite2D.play("Idle")

func _on_area_2d_body_entered(body: Node2D) -> void:
	if body.name == "Player":
		timer.start()
		$Enter.play()


func _on_timer_timeout() -> void:
	$AnimatedSprite2D.play("Pop")
	$Pop.play()
	$Timer2.start()
	scored.emit()

func _on_timer_2_timeout() -> void:
	queue_free()
	
func changeColor(r, g, b):
	var tween = get_tree().create_tween()
	
	var color = Color(r, g, b, 1.0)
	
	tween.tween_property($AnimatedSprite2D.material, "shader_parameter/color", color, 0.25)
